package com.thoughtworks.turtlemock.filemover;

import junit.framework.TestCase;

import java.io.File;

public class FileAdapterAcceptanceTest extends TestCase {
    private static final String A_NEW_FILE_NAME = "aNewFile.ext";
    private static final String C_DIR = "c:/";
    private File aFile;
    private FileAdaptee fileAdapter;
    private FileMover mover;
    private File target;

    protected void setUp() throws Exception {
        aFile = new File(A_NEW_FILE_NAME);
        aFile.createNewFile();
        target = new File(C_DIR + A_NEW_FILE_NAME);

        fileAdapter = new FileAdapter(aFile);
        mover = new FileMover(new FileAdapter(new File(C_DIR)));
    }

    protected void tearDown() throws Exception {
        if (aFile.exists()) {
            aFile.delete();
        }
        if (target.exists()) {
            target.delete();
        }
    }

    public void testTargetFileShouldNotExist() throws Exception {
        assertFalse(target.exists());
    }

    public void testShouldMoveFileToTargetDirAndBeRollbackable() throws Exception {
        mover.move(fileAdapter);
        assertTrue(target.exists());
        assertFalse(aFile.exists());

        mover.rollback();
        assertFalse(target.exists());
        assertTrue(aFile.exists());
    }
}
